<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('证书分配列表')" />
</head>
<body>
    <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="role-form">
                    <input type="hidden" id="cerId" name="cerId"  th:value="${cerId}">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>学号：</label>
                                <input type="text" name="stuNumber"/>
                            </li>
                            <li>
                                <label>学生姓名：</label>
                                <input type="text" name="stuName"/>
                            </li>
                            <li>
                                <label>所属班级：</label>
                                <input type="text" name="stuClass"/>
                            </li>
                            <li>
                                <label>所属专业：</label>
                                <input type="text" name="stuSpeciality"/>
                            </li>
                            <li>
                                <label>身份证：</label>
                                <input type="text" name="stuIdcard"/>
                            </li>
                            <li class="select-time">
                                <label>入学时间：</label>
                                <input type="text" class="time-input" id="startTime1" placeholder="开始时间" name="params[beginEnrollTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime1" placeholder="结束时间" name="params[endEnrollTime]"/>
                            </li>
                            <li class="select-time">
                                <label>毕业时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginGraduationTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endGraduationTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
    
            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="selectStudent()">
                    <i class="fa fa-plus"></i> 添加用户
                </a>
                <a class="btn btn-danger multiple disabled" onclick="cancelAuthStudentAll()" shiro:hasPermission="system:role:remove" type="hidden">
                    <i class="fa fa-remove"></i> 批量取消授权
                </a>
                <a class="btn btn-warning" onclick="closeItem()">
                    <i class="fa fa-reply-all"></i> 关闭
                </a>
            </div>
    
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
	    var prefix = ctx + "system/certificate/authStudentData";

        $(function() {
            var options = {
		        url: prefix + "/allocatedList",
		        queryParams: queryParams,
		        sortName: "stuNumber",
		        sortOrder: "desc",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'stuId',
                    title: '学生ID',
                    visible: false
                },
                {
                    field: 'stuNumber',
                    title: '学号'
                },
                {
                    field: 'stuName',
                    title: '学生姓名'
                },
                {
                    field: 'stuClass',
                    title: '所属班级'
                },
                {
                    field: 'stuSpeciality',
                    title: '所属专业'
                },
                {
                    field: 'stuIdcard',
                    title: '身份证'
                },
                {
                    field: 'enrollTime',
                    title: '入学时间'
                },
                {
                    field: 'graduationTime',
                    title: '毕业时间'
                },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		                var actions = [];
		                actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelAuthStudentData(\'' + row.stuId + '\')"><i class="fa fa-remove"></i>取消授权</a> ');
		                return actions.join('');
		            }
		        }]
            };
            $.table.init(options);
        });
		
		function queryParams(params) {
			var search = $.table.queryParams(params);
			search.cerId = $("#cerId").val();
			return search;
		}
		
		/* 分配学生-选择用户 */
		function selectStudent() {
			var url = prefix + '/selectStudent/' + $("#cerId").val();
		    $.modal.open("选择用户", url);
		}
		
		/* 分配学生-批量取消授权 */
		function cancelAuthStudentAll(stuId) {
		    var rows = $.table.selectFirstColumns();
       		if (rows.length == 0) {
       			$.modal.alertWarning("请至少选择一条记录");
       			return;
       		}
       		$.modal.confirm("确认要删除选中的" + rows.length + "条数据吗?", function() {
    			var data = { "cerId": $("#cerId").val(), "stuIds": rows.join() };
    			$.operate.submit(prefix + "/cancelAll", "post", "json", data);
    		});
		}
		
		/* 分配学生-取消授权 */
		function cancelAuthStudentData(stuId) {
			$.modal.confirm("确认要取消该用户角色吗？", function() {
				$.operate.post(prefix + "/cancel", { "cerId": $("#cerId").val(), "stuId": stuId });
		    })
		}
    </script>
</body>
</html>